// 依赖倒转原则
// Dependence Inversion Principle， DIP
// 
// 这里用一家银行有几个工作人员的例子来说明
//
#pragma once

#include <iostream>

/// @brief 银行工作人员抽象类 虚基类
class Banker
{
public:
	Banker() = default;
	virtual ~Banker() {}

	/// @brief 工作人员业务函数
	/// @details 纯虚函数
	virtual void doBusiness() = 0;

private:

};

/// @brief 负责存钱的人员
class SaveBanker : public Banker
{
public:
	SaveBanker() = default;
	virtual ~SaveBanker() {}

	/// @brief 存钱工作人员业务函数
	virtual void doBusiness() {
		std::cout << "存钱" << std::endl;
	}

private:

};

/// @brief 负责取钱的人员
class WithdrawBanker : public Banker
{
public:
	WithdrawBanker() = default;
	virtual ~WithdrawBanker() {}

	/// @brief 取钱工作人员业务函数
	virtual void doBusiness() {
		std::cout << "取钱" << std::endl;
	}

private:

};

/// @brief 负责转账的人员
class TransferBanker : public Banker
{
public:
	TransferBanker() = default;
	virtual ~TransferBanker() {}

	/// @brief 转账工作人员业务函数
	virtual void doBusiness() {
		std::cout << "转账" << std::endl;
	}

private:

};

// 上层业务
void DoBankBusiness(Banker* banker) {
	banker->doBusiness();

	if (banker != nullptr)
		delete banker;
}

int main() {
	Banker* saver = new SaveBanker;
	Banker* withdraw = new WithdrawBanker;
	Banker* transfer = new TransferBanker;

	DoBankBusiness(saver);
	DoBankBusiness(withdraw);
	DoBankBusiness(transfer);

	//delete saver;
	//delete withdraw;
	//delete transfer;
	return 0;
}


// void testDIP() {
// 	Banker* saver = new SaveBanker;
// 	Banker* withdraw = new WithdrawBanker;
// 	Banker* transfer = new TransferBanker;

// 	DoBankBusiness(saver);
// 	DoBankBusiness(withdraw);
// 	DoBankBusiness(transfer);

// 	//delete saver;
// 	//delete withdraw;
// 	//delete transfer;
	
// }
